//
//  SpecialTicketView.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/1/18.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class SpecialHeaderView: UIView {
    
    // 更多文本
    private lazy var moreLabel = UILabel(title: "更多", color: UIColor.gray,align: .right)
    // 特价机票
    private lazy var specialLabel = UILabel()
    // 右箭头
    private lazy var rightArrow = UIImageView()
    // 是否更多文本、右箭头
    public var isShowMore:Bool = true
    // 回调
    public var complete: (() -> Void)?
    
    public var text:String? {
        didSet {
            specialLabel.text = text!
        }
    }
    
    public var moreText:String? {
        didSet {
            moreLabel.text = moreText
        }
    }
    
    override func layoutSubviews() {
        // 标题
        specialLabel.font = UIFont.boldSystemFont(ofSize: 19)
        specialLabel.frame = CGRect(x: MARGIN, y: 0, width: frame.width * 0.4, height: frame.height)
        addSubview(specialLabel)
        if isShowMore {
            // 箭头
            let img = UIImage(named: "arrow_12x12")
            rightArrow.image = img
            rightArrow.contentMode = .scaleAspectFit
            let imgX = frame.width - MARGIN * 2
            rightArrow.frame = CGRect(x: imgX, y: frame.height * 0.5 - MARGIN * 0.5, width: MARGIN, height: MARGIN)
            addSubview(rightArrow)
            // 子标题
            moreLabel.font = UIFont.systemFont(ofSize: 13)
            let moreLabelX = frame.width -  MARGIN150 - MARGIN * 2
            moreLabel.frame = CGRect(x: moreLabelX, y: 0, width: MARGIN150, height: frame.height)
            addSubview(moreLabel)
            // 添加事件
            moreLabel.isUserInteractionEnabled = true
            moreLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(clickMore)))
        }
    }
    
    @objc func clickMore() -> Void {
        if let callback = complete {
            callback()
        }
    }
}
